package demoMod.nanaki.patches.events.city;

import basemod.ReflectionHacks;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.evacipated.cardcrawl.modthespire.lib.SpireReturn;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.events.AbstractImageEvent;
import com.megacrit.cardcrawl.events.city.TheLibrary;
import com.megacrit.cardcrawl.localization.EventStrings;
import com.megacrit.cardcrawl.vfx.cardManip.ShowCardAndObtainEffect;
import demoMod.nanaki.NanakiMod;
import demoMod.nanaki.cards.tempCards.AncientKnowledge;
import demoMod.nanaki.characters.NanakiCharacter;

public class TheLibraryPatch {
    public static final String ID = NanakiMod.makeID("The Library");
    private static final EventStrings eventStrings;
    public static final String NAME;
    public static final String[] DESCRIPTIONS;
    public static final String[] OPTIONS;

    @SpirePatch(
            clz = TheLibrary.class,
            method = SpirePatch.CONSTRUCTOR
    )
    public static class PatchConstructor {
        public static void Postfix(TheLibrary event) {
            if (AbstractDungeon.player instanceof NanakiCharacter) {
                event.imageEventText.setDialogOption(OPTIONS[5], new AncientKnowledge());
            }
        }
    }

    @SpirePatch(
            clz = TheLibrary.class,
            method = "buttonEffect"
    )
    public static class PatchButtonEffect {
        public static SpireReturn<Void> Prefix(TheLibrary event, int buttonPressed) {
            if (AbstractDungeon.player instanceof NanakiCharacter) {
                int screenNum = ReflectionHacks.getPrivate(event, TheLibrary.class, "screenNum");
                if (screenNum == 0 && buttonPressed == 2) {
                    AbstractDungeon.effectList.add(new ShowCardAndObtainEffect(new AncientKnowledge(), (float)(Settings.WIDTH / 2), (float)(Settings.HEIGHT / 2)));
                    event.imageEventText.updateBodyText(DESCRIPTIONS[5]);
                    ReflectionHacks.setPrivate(event, TheLibrary.class, "screenNum", 1);
                    event.imageEventText.updateDialogOption(0, OPTIONS[3]);
                    event.imageEventText.clearRemainingOptions();
                    AbstractImageEvent.logMetricObtainCard("The Library", "Singing", new AncientKnowledge());
                    return SpireReturn.Return(null);
                }
            }
            return SpireReturn.Continue();
        }
    }

    static {
        eventStrings = CardCrawlGame.languagePack.getEventString(ID);
        NAME = eventStrings.NAME;
        DESCRIPTIONS = eventStrings.DESCRIPTIONS;
        OPTIONS = eventStrings.OPTIONS;
    }
}
